
package com.idealighter.game.web.core;

/**
 * Http请求的返回.
 * 
 * @date 2016年2月23日 下午3:11:33
 *
 */
public class HttpRes {

  // res成功常量
  public static final int SUCCESS = 1;
  // res失败常量
  public static final int FAILURE = 0;

  // GM命令执行后的状态(0:失败，1:成功)
  private int res;
  // 失败时对失败原因的说明
  private String msg;
  // 有返回的GM命令的执行结果 。如果不是单个字符串或数值 则将结果序列化为json字符串;无返回是为空串
  private Object data;

  public HttpRes() {}

  /**
   * 构造函数.
   * 
   * @param res .
   * @param msg .
   * @param data .
   */
  public HttpRes(int res, String msg, Object data) {
    this.res = res;
    this.msg = msg;
    this.data = data;
  }

  /**
   * 返回成功的HttpRes.
   * 
   * @param msg .
   * @return .
   */
  public static HttpRes success(String msg) {

    return new HttpRes(SUCCESS, msg, "");
  }

  /**
   * 返回成功的HttpRes.
   * 
   * @param data .
   * @return .
   */
  public static HttpRes success(Object data) {

    return new HttpRes(SUCCESS, "", data);
  }

  /**
   * 返回成功的HttpRes.
   * 
   * @param msg .
   * @param data .
   * @return .
   */
  public static HttpRes success(String msg, Object data) {

    return new HttpRes(SUCCESS, msg, data);
  }

  /**
   * 返回失败的HttpRes.
   * 
   * @param msg .
   * @return .
   */
  public static HttpRes failure(String msg) {

    return new HttpRes(FAILURE, msg, "");
  }

  /**
   * 返回失败的HttpRes.
   * 
   * @param msg .
   * @param data .
   * @return .
   */
  public static HttpRes failure(String msg, Object data) {

    return new HttpRes(FAILURE, msg, data);
  }

  public int getRes() {
    return res;
  }

  public void setRes(int res) {
    this.res = res;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }
}
